package controllers;

import java.awt.event.ActionEvent;
import java.io.IOException;
import java.io.Serializable;

import common.ConIF;
import client.CCRMClient;
import ccrm.BoundryControl;
import ccrm.ClientMain;
import entitys.LoginUser;
import entitys.Product;
import entitys.Request;
import entitys.Session;
import entitys.User;
import enums.Command;
import enums.Result;
import boundarys.LoginGUI;


public class UserController {
	
	LoginGUI myGUI;
	
	public UserController(LoginGUI login)
	{
		this.myGUI=login;	
	}
	
	/**
	 * sends the server request to validate user login details
	 * @param userId
	 * @param password
	 * @return OK
	 */
	public static Result validateUser(String userId,String password)
	{
		Request r =new Request(Command.LOGIN,"123",new LoginUser(userId,password));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return Result.OK;
	}
	
	/**
	 * sends server a request to logout the user
	 * @param userId
	 * @param password
	 * @return OK
	 */
	public static Result LogoutUser(String userId,String password)
	{
		Request r =new Request(Command.LOGOUT,Session.getEmployee().getUserId(),new LoginUser(userId,password));
		
	
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
		return Result.OK;
	}

}
